{% extends 'admin/layout.html.twig' %}

{% set script_controller = 'review/list' %}

{% set menu = 'admin_course_review_tab' %}

{% block main %}

  <form id="review-search-form" class="form-inline well well-sm" action="" method="get" novalidate> 

    <div class="form-group">
      <select class="form-control" name="rating">
        {{ select_options({1:'admin.course_review.one_star'|trans, 2:'admin.course_review.two_stars'|trans, 3:'admin.course_review.three_stars'|trans, 4:'admin.course_review.four_stars'|trans, 5:'admin.course_review.five_stars'|trans}, app.request.get('rating'), 'admin.course_review.rate_option'|trans) }}
      </select>
    </div>

   {#  <div class="form-group">
      <input class="form-control" type="text" placeholder="课程编号" name="courseId" value="{{ app.request.get('courseId') }}">
    </div> #}
    
    <div class="form-group">
      <input class="form-control" type="text" placeholder="{{'admin.course_review.form.input.courseTitle.placeholer'|trans}}" name="courseTitle" value="{{ app.request.get('courseTitle') }}">
    </div>

    <div class="form-group">
      <input class="form-control" type="text" placeholder="{{'admin.course_thread.form.input.author.placeholer'|trans}}" name="author" value="{{ app.request.get('author') }}">
    </div>

    <div class="form-group">
      <input class="form-control" type="text" placeholder="{{'admin.course_review.form.input.content.placeholer'|trans}}" name="content" value="{{ app.request.get('content') }}">
    </div>

    <button class="btn btn-primary">{{'form.btn.search'|trans}}</button>
  </form>

  <div id="review-table-container">
    <table class="table table-striped table-hover" id="review-table">
      <thead>
        <tr>
          <th width="4%"><input type="checkbox"  data-role="batch-select"></th>
          <th width="55%">{{'admin.course_review.content_th'|trans}}</th>
          <th width="8">{{'admin.course_review.rate_th'|trans}}</th>
          <th width="15%">{{'admin.course_thread.author_th'|trans}}</th>
          <th width="10%">{{'admin.course_review.completed_progress_th'|trans}}</th>
          <th width="8%">{{'admin.course_thread.operation_th'|trans}}</th>
        </tr>
      </thead>
      <tbody>
        {% for review in reviews %}
          {% set author = users[review.userId]|default(null) %}
          {% set courseSet = courseSets[review.courseSetId]|default(null) %}
          {% set course = courses[review.courseId]|default(null) %}
          <tr id="review-table-tr-{{review.id}}" data-role="item">
            <td><input type="checkbox" value="{{review.id}}" data-role="batch-item"></td>
            <td>
              <div class="short-long-text">
                <div class="short-text">
                  {{ review.content|plain_text(60) }} <span class="text-muted trigger">({{'admin.course_thread.expand_td'|trans}})</span>
                </div>
                <div class="long-text">{{ review.content|nl2br }} <span class="text-muted trigger">({{'admin.course_thread.collapse_td'|trans}})</span></div>
              </div>
              <div class="mts">
                {% if courseSet %}
                  <a class="text-success text-sm" href="{{ path('course_show', {id: courseSet.defaultCourseId}) }}" class="text-success" target="_blank">{{ courseSet.title }}</a>
                {% endif %}

                {% if course %}
                  <span class="text-muted mhs text-sm">&raquo;</span>
                  <a class="text-success text-sm" href="{{ path('course_show', {id:course.id}) }}" class="text-success" target="_blank">{{ course.title }}</a>
                {% endif %}
              </div>
            </td>
            <td>{{ review.rating }}{{'admin.course_review.star'|trans}}</td>
            <td>
              {{ admin_macro.user_link(author) }}<br>
              <span class="text-muted">{{review.createdTime|date('Y-n-d H:i')}}</span>
            </td>
            <td>{% if review.meta %} {{ review.meta.learnedNum }}/{{ review.meta.lessonNum }} {% endif %}</td>
            <td>
              <button class="btn btn-default btn-sm" data-role="item-delete" data-name="{{'admin.course_review.content'|trans}}" data-url="{{ path('admin_review_delete', {id:review.id}) }}">{{'form.btn.delete'|trans}}</button>
            </td>
          </tr>
        {% else %}
          <tr><td colspan="20"><div class="empty">{{'site.datagrid.empty'|trans}}</div></td></tr>
        {% endfor %}
      </tbody>
    </table>

    <div>
      <label class="checkbox-inline"><input type="checkbox" data-role="batch-select"> {{'admin.course_thread.select_all_btn'|trans}}</label>
      <button class="btn btn-default btn-sm mlm" data-url="{{ path('admin_review_batch_delete') }}" data-role="batch-delete" data-name="{{ 'admin.course_review.content'|trans }}">{{'form.btn.delete'|trans}}</button>
    </div>
  </div>

  {{ admin_macro.paginator(paginator) }}

{% endblock %}
